package com.nutstudio.feilproject.manager;

import android.util.Log;

import com.nutstudio.feilproject.bean.TestBean;
import com.nutstudio.feilproject.net.RetrofitHelper;
import com.nutstudio.feilproject.net.RetrofitService;
import com.nutstudio.feilproject.net.UploadRetrofitHelper;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.adapter.rxjava2.Result;

/**
 * 数据处理
 * Created by yangle on 2017/6/27.
 */

public class DataManager {

    private static DataManager dataManager;
    public RetrofitService retrofitService;



    public static DataManager getInstance() {
        return dataManager == null ? dataManager = new DataManager() : dataManager;
    }

    private DataManager() {
        retrofitService = RetrofitHelper.getInstance().getRetrofitService();
    }


    /**
     * 获取
     *
     * @param code 返回码
     * @return Observable<TestBean>
     */
    public Observable<TestBean> getTestInfo(int code) {
        return retrofitService.getTestInfoRx(code);
    }


    public Observable<TestBean> postTestInfo(int code) {
        return retrofitService.postTestInfoRx(code);
    }


    public Observable<TestBean> uploadFiles(String des, List<File> fileList) {
        Map<String, RequestBody> maps = new HashMap<>();
        for (int i = 0; i < fileList.size(); i++) {
            File file = fileList.get(i);
            maps.put("file\";filename=\"" + file.getName(), RequestBody.create(MediaType.parse("image/png"), file));
        }
        return retrofitService.uploadFiles(des, maps);
    }



}
